package com.acmedcare.framework.normal.sample;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

public class NormalSampleApplication {

  public static void main(String[] args) throws IOException, InterruptedException {

    String localSrc = "/Users/abel/Desktop/demo-1.0-SNAPSHOT.jar";
    String destSrc = "hdfs://192.168.1.17:9000/acmedcare/demo-1.0-SNAPSHOT.jar";
    InputStream input = new BufferedInputStream(new FileInputStream(localSrc));
    URI uri = URI.create("hdfs://192.168.1.17:9000");
    Configuration conf = new Configuration();
    //conf.set("fs.defaultFS", "hdfs://192.168.1.17:9000");
    FileSystem fileSystem = FileSystem.get(uri, conf, "root");

    OutputStream out = fileSystem.create(new Path(destSrc), () -> System.out.println("上传完一个文件"));
    IOUtils.copyBytes(input, out, 4096, true);
    System.out.println("this is demo sample");
    System.out.println("hello world exchange center");
  }
}